<{include file="tpl/filter.tpl"}>

<div>
    
</div>

<{include file="tpl/grid.tpl"}>
	
<script>
	$(function(){
		
		//批准
		$(document).on('click','a[name="approve"]',function(){
		//$('a[name="approve"]').click(function(){ 
			_this = $(this);
			layer.confirm('确定批准该申请？', {
				btn: ['确定','取消'] //按钮
				,skin: 'layui-layer-molv'
			}, function(){
				var id = _this.attr('data-id');
				setStatus(id,2,_this);
			}, function(){
				//console.log('取消');
            });
		});
		
		//驳回
		$(document).on('click','a[name="reject"]',function(){
		//$('a[name="reject"]').click(function(){
			_this = $(this);
			layer.confirm('确定驳回该申请？', {
				btn: ['确定','取消'] //按钮
				,skin: 'layui-layer-molv'
			}, function(){
				var id = _this.attr('data-id');
				setStatus(id,3,_this);
			}, function(){
				//console.log('取消');
            });
		});
		  
	});
	
function setStatus(id,status,_this){
	var _this = _this;
	var g = $('input[name="g"]').val();
	var url = '?r=insidePlayer/setStatus&g='+g;
	
	var html = "";
	var action = '<a href="javascript:;" name="xinfo" data-id="'+id+'"><font color="blue">审批信息</font></a>';

	$.ajax({
    	type : 'POST',
    	url : url,
		data : {'id':id,'status':status},
		dataType :'JSON',
		success : function(res){
			if(res.status == 1){
				layer.alert(res.msg, {icon: 1, skin: 'layui-layer-molv'});
				if(res.data == 2){
		            html = '<font color="blue">已批准</font>';
	            }else if(res.data == 3){
		            html = '<font color="red">已驳回</font>';
	            }
				_this.parent('div').parent('td').parent('tr').find('.xstatus').html(html);
				_this.parent('div').html(action);
			}else{
			    layer.alert(res.msg, {icon: 2, skin: 'layui-layer-molv'});
			}
		}
	});
}


$(document).on('click','a[name="xinfo"]',function(){
	var id = $(this).attr('data-id');
	var g = $('input[name="g"]').val();
    $url = '?r=insidePlayer/getApproval&g='+g+'&id='+id;
    layer.open({
    	skin: 'layui-layer-molv'
    	,type: 2
    	,area: ['400px', '600px']
    	,title:'审批信息'
    	,content: $url
    	,btn: ['确定']   			
    });
});
</script>